home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / checkbox / registries / directory.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-10-12  |  2.5 KB  |  60 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import os
  5. import logging
  6. from checkbox.properties import Path
  7. from checkbox.registry import Registry
  8.  
  9. class DirectoryRegistry(Registry):
  10.     '''Base registry for containing directories.
  11.  
  12.     The default behavior is to return the files within a directory
  13.     separated by newlines.
  14.  
  15.     Subclasses should define a directory parameter.
  16.     '''
  17.     directory = Path()
  18.     
  19.     def __init__(self, directory = None):
  20.         super(DirectoryRegistry, self).__init__()
  21.         if directory is not None:
  22.             self.directory = directory
  23.         
  24.  
  25.     
  26.     def __str__(self):
  27.         logging.info('Reading directory: %s', self.directory)
  28.         return '\n'.join(os.listdir(self.directory))
  29.  
  30.     
  31.     def items(self):
  32.         return []
  33.  
  34.  
  35.  
  36. class RecursiveDirectoryRegistry(DirectoryRegistry):
  37.     '''Variant of the DirectoryRegistry that recurses into subdirectories.'''
  38.     
  39.     def __str__(self):
  40.         logging.info('Reading directory: %s', self.directory)
  41.         return '\n'.join(self._listdir(self.directory))
  42.  
  43.     
  44.     def _listdir(self, root, path = ''):
  45.         files = []
  46.         
  47.         try:
  48.             for file in os.listdir(os.path.join(root, path)):
  49.                 pathname = os.path.join(path, file)
  50.                 if os.path.isdir(os.path.join(root, pathname)):
  51.                     files.extend(self._listdir(root, pathname))
  52.                     continue
  53.                 files.append(pathname)
  54.         except OSError:
  55.             pass
  56.  
  57.         return files
  58.  
  59.  
  60.